// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'Axios'

import ElementUI from 'element-ui' // 引入element-ui组件库
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI)

Vue.config.productionTip = false
Vue.prototype.$request = axios

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

router.beforeEach((to, from, next) => {
  // console.log('页面发生跳转')
  if (to.path !== '/login') {
    axios({
      url: '/admin/index/getinfo',
      method: 'get',
    }).then((result) => {
      const res = result.data
      // console.log('获取用户信息返回的数据', res)
      if (res.status) {
        console.log('登录成功')
      } else {
        console.log('登录失败')
        next('/login')
      }
    })
  }
  next()
})
